<!--
 * @Author: your name
 * @Date: 2020-11-26 08:59:24
 * @LastEditTime: 2021-01-05 16:36:46
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \wms2\src\views\basicInfo\contract\edit_list\contractEdit.vue
-->
<template>
  <div class="root-edit-list">

    <el-tabs type="border-card"  style="padding:15px;">
      <el-tab-pane label="合同信息">
        <formCom ref="formCom" type="edit" index="purchase"/>
      </el-tab-pane>
      <el-tab-pane label="作业费">
        <tableBar ref="tableBar" type="edit" index="purchase"/>
      </el-tab-pane>
    </el-tabs>
    <el-button  type="primary" style="margin-top:15px;margin-left:15px" plain @click="funcSubmit()">提交</el-button>
</div>
</template>
<script>
import formCom from "../components/form_bar";
import tableBar from "../components/table_bar";
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import XEUtils from 'xe-utils'
import VXEUtils from 'vxe-utils'
import VXETablePluginElement from 'vxe-table-plugin-element'
import 'vxe-table-plugin-element/dist/style.css'
import shipmentSelect3 from '@/views/components/shipmentSelect3.vue'
import warehouseSelect from '@/views/components/warehouseSelect.vue'
import { contractEdit } from '@/api/basicInfo'

Vue.use(VXETable, VXEUtils, XEUtils, { mounts: ['cookie'] })
VXETable.use(VXETablePluginElement)
export default {
  data: () => ({}),
  components: {
    formCom,
    tableBar
  },
  methods:{
    // 提交
    funcSubmit() {
      this.$refs.formCom.$refs["form"].validate((valid) => {
        if (valid) {
          if(this.$refs.tableBar.tableData[0].feeType){
            this.$refs.tableBar.$refs.xTable.validate((valids) => {
              if(valids){
                const rLoading = this.openLoading();
                this.$refs.formCom.form.contractOperationCostList = this.$refs.tableBar.tableData
                const data = this.$refs.formCom.form
                contractEdit(data).then((response) => {
                  rLoading.close();
                }).then(() => {
                  this.$eventBus.$emit('refreshList')
                  this.$store.dispatch("tagsView/delView", this.$route);
                  this.$router.push({
                    path: "/basicInfo/contract"
                  });
                })
              }else{
                this.$message.error("请完善作业费!");
              }
            })
          }else{
            const rLoading = this.openLoading();
            this.$refs.formCom.form.contractOperationCostList = this.$refs.tableBar.tableData
            const data = this.$refs.formCom.form
            contractEdit(data).then((response) => {
              rLoading.close();
            }).then(() => {
              this.$store.dispatch("tagsView/delView", this.$route);
              this.$router.push({
                path: "/basicInfo/contract"
              });
            })
          }


        }
        else {
          this.$message.error("请输入有效值!");
        }

        });
      },

  }

};
</script>
<style lang="scss" scoped>
.root-edit-list {
  padding: 20px;
  background-color: rgba(240, 242, 250, 1);
}
</style>

